package org.oak.controller;

import org.oak.model.User;
import org.oak.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * org.oak.controller.UserController
 *
 * @author ZRS
 * @version V1.0
 * @since 2025/10/29 18:37
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    UserService userService;


    @GetMapping("/{id}")
    public Map<String, Object> getUserById(@PathVariable(value = "id") Long id) {
        User user = userService.getUserById(id);
        Map<String, Object> map = new HashMap<>();
        map.put("data", user);
        map.put("code", 200);
        return map;
    }

    @PutMapping("/modify")
    public Map<String, Object> modifyUser(@RequestBody User user) {
        userService.updateUser(user);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        return map;
    }


    @GetMapping("/clearCache")
    public Map<String, Object> clearCache() {
        userService.clearCache();
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        return map;
    }

    @DeleteMapping("/delete/{id}")
    public Map<String, Object> delete(Long id) {
        userService.deleteUser(id);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        return map;
    }
}
